home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 51 / Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso / -in_the_mag- / workbench / term_4.8 / extras / source / gtlayout-source.lha / LT_Rebuild.c < prev    next >
C/C++ Source or Header  |  1997-05-08  |  7KB  |  342 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1997 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. #include "Assert.h"
  15.  
  16.  
  17. /*****************************************************************************/
  18.  
  19.  
  20. VOID
  21. LTP_Erase(LayoutHandle *Handle)
  22. {
  23.     struct Window *Window = Handle->Window;
  24.  
  25.     EraseRect(&Handle->RPort,Window->BorderLeft,Window->BorderTop,Window->Width - (Window->BorderRight + 1),Window->Height - (Window->BorderBottom + 1));
  26. }
  27.  
  28.  
  29. /*****************************************************************************/
  30.  
  31.  
  32. /****** gtlayout.library/LT_RebuildTagList ******************************************
  33. *
  34. *   NAME
  35. *    LT_RebuildTagList -- Rebuild the user interface after modifying it.
  36. *
  37. *   SYNOPSIS
  38. *    Success = LT_RebuildTagList(Handle,Clear,TagList);
  39. *       D0                         A0    D0     A1
  40. *
  41. *    BOOL LT_RebuildTagList(LayoutHandle *,BOOL,struct TagItem *);
  42. *
  43. *    Success = LT_RebuildTags(Handle,Clear,...);
  44. *
  45. *    BOOL LT_RebuildTags(LayoutHandle *,BOOL,...);
  46. *
  47. *   FUNCTION
  48. *    Certain aspects of the user interface can be changed at run time,
  49. *    such as button labels. This routine will let you rebuild the interface
  50. *    based upon the data supplied at creation time and your subsequent
  51. *    changes. Before you make any vital changes, it is recommended to
  52. *    lock the window using LT_LockWindow() in order to avoid clashes
  53. *    with the Intuition and GadTools subsystems.
  54. *
  55. *   INPUTS
  56. *    Handle - Pointer to LayoutHandle structure.
  57. *
  58. *    Clear - Pass in TRUE if you wish to have the window contents
  59. *        cleared before they are rebuild. This will introduce
  60. *        some visual hashing.
  61. *
  62. *    TagList - Attributes controlling the layout process.
  63. *
  64. *
  65. *    Valid tags include:
  66. *
  67. *    LAWN_Bounds (struct IBox *) - Boundaries in which the window
  68. *        should be centered.
  69. *
  70. *    LAWN_ExtraWidth (LONG) - Extra space to add to the window
  71. *        width.
  72. *
  73. *    LAWN_ExtraHeight (LONG) - Extra height to add to the window
  74. *        height.
  75. *
  76. *   RESULT
  77. *    Success - TRUE indicates that the interface was rebuilt,
  78. *        FALSE indicates trouble; it is recommended to
  79. *        call LT_DeleteHandle() on your LayoutHandle as
  80. *        soon as possible as the previous operation may
  81. *        have left the user interface in an inoperable
  82. *        state.
  83. *
  84. ******************************************************************************
  85. *
  86. */
  87.  
  88. BOOL LIBENT
  89. LT_RebuildTagList(REG(a0) LayoutHandle *handle,REG(d0) BOOL clear,REG(a1) struct TagItem *TagParams)
  90. {
  91.     struct TagItem    *item,
  92.                     *list;
  93.     struct IBox        *bounds = NULL;
  94.     LONG             RightEdge,
  95.                      BottomEdge;
  96.  
  97.     list = TagParams;
  98.  
  99.     while(item = NextTagItem(&list))
  100.     {
  101.         switch(item->ti_Tag)
  102.         {
  103.             case LAWN_Bounds:
  104.  
  105.                 bounds = (struct IBox *)item->ti_Data;
  106.                 break;
  107.         }
  108.     }
  109.  
  110.     if(handle)
  111.     {
  112.         struct Gadget    *gadget,
  113.                         *next;
  114.         ObjectNode        *node;
  115.         LONG             left,top;
  116.         struct IBox         newBounds;
  117.         struct Image    **ImagePtr;
  118.  
  119.         if(!handle->SizeVerified)
  120.         {
  121.             LTP_StripGadgets(handle,handle->List);
  122. #ifdef DO_BOOPSI_KIND
  123.             LTP_StripGadgets(handle,(struct Gadget *)handle->BOOPSIList);
  124. #endif    /* DO_BOOPSI_KIND */
  125.         }
  126.         gadget = handle->List;
  127.  
  128.         while(gadget)
  129.         {
  130.             if(GETOBJECT(gadget,node))
  131.             {
  132.                 LTP_PutStorage(node);
  133.  
  134.                 ImagePtr = NULL;
  135.  
  136.                 switch(node->Type)
  137.                 {
  138. #ifdef DO_GAUGE_KIND
  139.                     case GAUGE_KIND:
  140.  
  141.                         node->Special.Gauge.LastPercentage = -1;
  142.                         break;
  143. #endif    /* DO_GAUGE_KIND */
  144.  
  145.                     case BUTTON_KIND:
  146.  
  147.                         ImagePtr = &node->Special.Button.ButtonImage;
  148.                         break;
  149.  
  150.                     case PICKER_KIND:
  151.  
  152.                         ImagePtr = &node->Special.Picker.Image;
  153.                         break;
  154.  
  155.                     case TAPEDECK_KIND:
  156.  
  157.                         ImagePtr = &node->Special.TapeDeck.ButtonImage;
  158.                         break;
  159.  
  160.                     case INCREMENTER_KIND:
  161.  
  162.                         ImagePtr = &node->Special.Incrementer.Image;
  163.                         break;
  164.  
  165.                     case STRING_KIND:
  166.                     case FRACTION_KIND:
  167.  
  168.                         if(!node->Special.String.Backup)
  169.                             node->Special.String.Backup = (STRPTR)LTP_Alloc(handle,node->Special.String.MaxChars + 1);
  170.  
  171.                         if(node->Special.String.Backup)
  172.                         {
  173.                             strcpy(node->Special.String.Backup,((struct StringInfo *)gadget->SpecialInfo)->Buffer);
  174.  
  175.                             node->Special.String.String = node->Special.String.Backup;
  176.                         }
  177.  
  178.                         node->Special.String.Picker = NULL;
  179.  
  180.                         node->Special.String.LeftIncrementer    = NULL;
  181.                         node->Special.String.RightIncrementer    = NULL;
  182.  
  183.                         break;
  184.  
  185.                     case TEXT_KIND:
  186.  
  187.                         node->Special.Text.Picker = NULL;
  188.                         break;
  189.  
  190.                     case INTEGER_KIND:
  191.  
  192.                         node->Special.Integer.LeftIncrementer    = NULL;
  193.                         node->Special.Integer.RightIncrementer    = NULL;
  194.  
  195.                         break;
  196.                 }
  197.  
  198.                 if(ImagePtr)
  199.                 {
  200.                     DisposeObject(*ImagePtr);
  201.  
  202.                     *ImagePtr = NULL;
  203.                 }
  204.  
  205.                 node->Host = NULL;
  206.             }
  207.  
  208.             gadget = gadget->NextGadget;
  209.         }
  210.  
  211.         FreeGadgets(handle->List);
  212.  
  213.         handle->List = NULL;
  214.  
  215. #ifdef DO_BOOPSI_KIND
  216.         gadget = (struct Gadget *)handle->BOOPSIList;
  217.  
  218.         while(gadget)
  219.         {
  220.             next = gadget->NextGadget;
  221.  
  222.             if(GETOBJECT(gadget,node))
  223.             {
  224.                 DisposeObject(gadget);
  225.  
  226.                 if(node->Type == BOOPSI_KIND)
  227.                 {
  228.                     if(node->Special.BOOPSI.ClassBase)
  229.                     {
  230.                         CloseLibrary(node->Special.BOOPSI.ClassBase);
  231.  
  232.                         node->Special.BOOPSI.ClassBase = NULL;
  233.                     }
  234.                 }
  235.  
  236.                 node->Host = NULL;
  237.             }
  238.  
  239.             gadget = next;
  240.         }
  241.  
  242.         handle->BOOPSIList = NULL;
  243.         handle->BOOPSIPrevious = NULL;
  244. #endif    /* DO_BOOPSI_KIND */
  245.  
  246.         LTP_Free(handle,handle->GadgetArray,sizeof(struct Gadget *) * handle->Count);
  247.  
  248.         handle->GadgetArray = NULL;
  249.  
  250.         handle->Count = handle->Index = 0;
  251.  
  252.         LTP_ResetGroups(handle->TopGroup);
  253.  
  254.         if(!bounds)
  255.         {
  256.             bounds = &newBounds;
  257.  
  258.             newBounds.Left        = 0;
  259.             newBounds.Top        = 0;
  260.             newBounds.Width        = handle->Window->Width;
  261.             newBounds.Height    = handle->Window->Height;
  262.         }
  263.  
  264.         left        = handle->Window->BorderLeft;
  265.         top            = handle->Window->BorderTop;
  266.         RightEdge    = handle->Window->BorderRight;
  267.         BottomEdge    = handle->Window->BorderBottom;
  268.  
  269.         if(!handle->FlushLeft)
  270.         {
  271.             left        += handle->InterWidth;
  272.             RightEdge    += handle->InterWidth;
  273.         }
  274.  
  275.         if(!handle->FlushTop)
  276.         {
  277.             top            += handle->InterHeight;
  278.             BottomEdge    += handle->InterHeight;
  279.         }
  280.  
  281.         LTP_CreateGadgets(handle,bounds,left,top,left + RightEdge,top + BottomEdge);
  282.  
  283.         if(handle->Failed)
  284.         {
  285.             handle->SizeVerified = FALSE;
  286.  
  287.             LTP_Erase(handle);
  288.  
  289.             RefreshWindowFrame(handle->Window);
  290.  
  291.             return(FALSE);
  292.         }
  293.  
  294.         if(clear)
  295.         {
  296.             LTP_Erase(handle);
  297.  
  298.             if(!handle->SizeVerified)
  299.                 RefreshWindowFrame(handle->Window);
  300.         }
  301.  
  302.         handle->SizeVerified = FALSE;
  303.  
  304.         LTP_AddGadgets(handle);
  305.  
  306.         LTP_SelectInitialActiveGadget(handle);
  307.  
  308.         return(TRUE);
  309.     }
  310.     else
  311.         return(FALSE);
  312. }
  313.  
  314.  
  315. /*****************************************************************************/
  316.  
  317.  
  318. BOOL
  319. LT_RebuildTags(LayoutHandle *Handle,BOOL Clear,...)
  320. {
  321.     va_list VarArgs;
  322.     BOOL    Result;
  323.  
  324.     va_start(VarArgs,Clear);
  325.     Result = LT_RebuildTagList(Handle,Clear,(struct TagItem *)VarArgs);
  326.     va_end(VarArgs);
  327.  
  328.     return(Result);
  329. }
  330.  
  331.  
  332. /*****************************************************************************/
  333.  
  334.  
  335. BOOL LIBENT
  336. LT_Rebuild(REG(a0) LayoutHandle *handle,REG(a1) struct IBox *bounds,REG(a2) LONG extraWidth,REG(d0) LONG extraHeight,REG(d1) BOOL clear)
  337. {
  338.     return(LT_RebuildTags(handle,clear,
  339.         LAWN_Bounds,bounds,
  340.     TAG_DONE));
  341. }
  342.